package cn.itcast.bos.web.action.system;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;

import cn.itcast.bos.domain.system.Role;
import cn.itcast.bos.service.system.RoleService;
import cn.itcast.bos.web.action.common.BaseAction;

/**
 * 角色的相关方法
 * 
 * @author 艾欣
 *
 */
@ParentPackage("json-default")
@Controller
@Namespace("/")
@Scope("prototype")
public class RoleAction extends BaseAction<Role> {
	// 注入角色的业务层
	@Autowired
	private RoleService rs;

	/**
	 * 查询所有角色的方法
	 */
	@Action(value = "role_list", results = { @Result(name = "success", type = "json") })
	public String list() {
		// 调用业务层查询数据
		List<Role> list = rs.finAll();
		// 压入值栈
		ActionContext.getContext().getValueStack().push(list);
		return SUCCESS;

	}
	//接收前台数据,属性驱动
	//前台的权限选择和菜单选择
	private String[] permissionIds;
	private String menuIds;
	
	/**
	 * 添加角色的方法
	 */
	@Action(value="role_save",results={@Result(name="success",type="redirect",location="pages/system/role.html")})
	public String save(){
		//调用业务层保存数据
		rs.save(model,permissionIds,menuIds);
		return SUCCESS;
	}
}
